--资源栏

class.resources_panel = extends(class.panel) {
    new = function (parent,x,y,width,height)
        local panel = class.resources_panel:builder 
        {
            parent = parent,
            x = x,
            y = y,
            w = width,
            h = height,
        }
        return panel
    end,

    -- 添加资源类型
    add_type = function(self,name,art)
        self.types = self.types or {}
        local icon = self:add_panel(art,0,0,self.w,self.h)
        icon.name = name
        icon.text = icon:add_text('',icon.w+5,0,0,self.h,10,4)
        icon.text:set_color(0xffffcc00)
        table.insert(self.types,icon)
    end,

    -- 显示资源
    set_info = function(self,info)
        local info = info or {}
        local position_x = 0
        for i,icon in ipairs(self.types) do
            local num = info[icon.name]
            if num and num~=0 then
                icon:set_position(position_x,0)
                icon.text:set_text(('%0.f'):format(num))
                position_x = position_x + icon.text.x + icon.text:get_width() + 36
                icon:show()
            else
                icon:hide()
            end
        end
        return position_x>0
    end,
}